#ifndef DCSDBOPERATOR_H
#define DCSDBOPERATOR_H

#include "sqliteoperator.h"

typedef enum videoSrc
{
    VIDEOSRC_EN_EMMC = 0,
    VIDEOSRC_EN_SDCARD,
    VIDEOSRC_EN_UDISK,
    VIDEOSRC_EN_NULL,
} videoSrc_en;

typedef enum udpInterFace
{
    UDP_IFACE_EN_WAN = 0,
    UDP_IFACE_EN_LAN,
} udpInterFace_en;

typedef struct masterParam
{
    quint8 id;
    quint8 slaveNum;            /*分控数*/
    quint8 slaveStartId;        /*分控起始ID*/
    quint8 mainVideoSrc;        /*主视频源*/
    quint8 backupVideoSrc;
    quint8 fps;
    quint8 mainNtpSrc;
    quint8 playMode;
    quint8 backLightLvl;
    quint8 turnoffBackLight;
} masterParam_st;

typedef struct slaveParam
{
    quint8 id;
    quint8 slaveId;             /*分控ID*/
    quint16 chipType;           /*芯片类型*/
    quint16 portChannelNum;     /*端口通道数*/
    quint8 gravLvl;             /*灰度等级*/
    quint16 clockFreq;          /*时钟频率*/
    quint16 clockFreqRead;
    quint8 ch0FineTune;
    quint8 dutyRate;            /*占空比*/
    quint8 grayFilte;           /*低灰过滤*/
    quint8 colorNum;            /*颜色数*/
    quint8 oe;
    quint8 gammaTuneType;       /*伽玛值设置方式，0表示通道整体设置，1表示通道分别设置，其他值无效，默认为0*/
    quint16 gamma[4];
    quint8 brightnessTuneType;  /*亮度调节设置方式，0表示通道亮度整体设置，1表示通道亮度分别设置，其他值无效，默认为0*/
    quint16 brightness[4];
    quint8 refleshType;         /*刷新频率方式选择，0表示手动设置刷新频率，1表示自动设置刷新频率，其他值无效，默认为1*/
    quint8 refleshValue;        /*刷新频率数值，刷新频率范围会根据芯片类型、带载、频率、灰度等级等因素自动调整，默认值根据芯片而定*/
    quint8 current_gain[4];     /*电流增益值，默认值待定，分别代表A、B、C、D四通道的电流数值；*/
    quint8 outputInverse;       /*输出反向，0表示不反向，1表示反向，默认为0不反向；*/
    quint8 addrPinDefault;      /*地址线默认电平为高，0表示为低，1表示为高，默认为1*/
    quint8 hold;                /*信号断开显示状态，0表示保留最后一帧，1表示黑屏，默认为为0*/
} slaveParam_st;

typedef struct playListsItem
{
    quint8 id;
    QString path;
//    QString md5sum;
//    quint32 frameNum;
//    quint8 fps;
//    bool isTimerTrigger;
//    bool isPlayImmediately;
//    quint8 startYear;
//    quint8 startMonth;
//    quint8 startDay;
//    quint8 startHour;
//    quint8 startMinute;
//    quint8 startSecond;
//    quint8 endYear;
//    quint8 endMonth;
//    quint8 endDay;
//    quint8 endHour;
//    quint8 endMinute;
//    quint8 endSecond;
//    bool isRepeatable;
//    quint8 weekMask[7];
//    quint8 syncType;
//    quint16 slaveStartId;
//    quint8 sectorPerFrame[128];
//    quint8 slaveNum;
//    quint8 sectorPerSlaveFrame;
} playListsItem_st;

class DCSDbOperator
{
public:
    DCSDbOperator();

    ~DCSDbOperator();

    static bool setMasterParameterSlaveNum(quint8 slaveNum);

    static bool getMasterParameterSlaveNum(quint8 &slaveNum);

    static bool setMasterParameterFPS(quint8 fps);

    static bool getMasterParameterFPS(quint8 &fps);

    static bool setMasterParameterPlayMode(quint8 mode);

    static bool getMasterParameterPlayMode(quint8 &mode);

    static bool setMasterParameter(struct masterParam &para);

    static bool getMasterParameter(struct masterParam &para);

    static bool setMasterParameterMainVideoSrc(quint8 src);

    static bool getMasterParameterMainVideoSrc(quint8 &src);

    static bool setMasterParameterBackupVideoSrc(quint8 src);

    static bool getMasterParameterBackupVideoSrc(quint8 &src);

    static bool setMasterParameterInterface(quint8 iface);

    static bool getMasterParameterInterface(quint8 &iface);

    bool clearPlayLists();

    static bool addPlayItem(struct playListsItem &item);

    static bool insertPlayItem(quint8 index, struct playListsItem &item);

    static bool getPlayLists(QList<QString> &lists);

    void open();

    void close();

private:
    SqliteOperator *mSqlopt;
};

#endif // DCSDBOPERATOR_H
